<?php

namespace App\Http\Middleware;

use Closure;

class CheckAdminLogin
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string   $param 中间件传参 在绑定中间件时使用:传参 middleware(['ckadmin:login'])
     * @return mixed
     */
    public function handle($request, Closure $next, $param='')
    {
        //
        if(!auth()->check()){
            return redirect(route('admin.login'))
                ->withErrors(['error'=>'请先登录']);
        }
        //如果没有停止,则向后执行
        return $next($request);
    }
}
